package com.smartleanx.module.hrm.controller.admin.salary;

import com.github.pagehelper.PageInfo;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.module.hrm.dal.dataobject.dingDing.SystemAttendanceTeam;
import com.smartleanx.module.hrm.dal.dataobject.dingDing.SystemFalseDiligence;
import com.smartleanx.module.hrm.service.dingDing.SystemFalseDiligenceService;
import com.smartleanx.module.hrm.service.salary.SystemAttendanceTeamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "管理后台-扣款规则 ")
@RestController
@RequestMapping("/hrm/system/deductionRule")
public class HrmDeductionRuleV2Controller {
    @Autowired
    private SystemAttendanceTeamService systemAttendanceTeamService;

    @Autowired
    private SystemFalseDiligenceService systemFalseDiligenceService;

    //缺卡等考勤异常扣款规则
    @GetMapping("/selectPage")
    public CommonResult<Object> selectPage(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageInfo<SystemAttendanceTeam> dingAttendanceTeamPageInfo = systemAttendanceTeamService.selectPage(pageNum, pageSize);
        return CommonResult.success(dingAttendanceTeamPageInfo);
    }

    @GetMapping("/selectInfo")
    public CommonResult<Object> selectInfo(@RequestParam("id") Integer id) {
        SystemAttendanceTeam dingAttendanceTeam = systemAttendanceTeamService.selectOne(id);
        return CommonResult.success(dingAttendanceTeam);
    }

    @PostMapping("/save")
    public CommonResult<Object> save(@RequestBody SystemAttendanceTeam dingAttendanceTeam) {
        systemAttendanceTeamService.saveDeductionRule(dingAttendanceTeam);
        return CommonResult.success("操作成功");
    }

    @PostMapping("/update")
    public CommonResult<Object> update(@RequestBody SystemAttendanceTeam dingAttendanceTeam) {
        systemAttendanceTeamService.updateDeductionRule(dingAttendanceTeam);
        return CommonResult.success("操作成功");
    }

    @PostMapping("/remove/{id}")
    public CommonResult<Object> remove(@PathVariable(value = "id") Integer id) {
        systemAttendanceTeamService.removeDeductionRule(id);
        return CommonResult.success("操作成功");
    }



    //========================================================== 请假扣款规则 ===================================================================================
    @GetMapping("/selectDingFalseDiligenceByInfo/{id}")
    public CommonResult<Object> selectDingFalseDiligenceByInfo(@PathVariable(value = "id") Integer id) {
        SystemFalseDiligence dingFalseDiligence = systemFalseDiligenceService.selectByInfo(id);
        return CommonResult.success(dingFalseDiligence);
    }

    @PostMapping("/updateDingFalseDiligence")
    public CommonResult<Object> updateDingFalseDiligence(@RequestBody SystemFalseDiligence dingFalseDiligence) {
        systemFalseDiligenceService.update(dingFalseDiligence);
        return CommonResult.success("操作成功");
    }

    @PostMapping("/saveDingFalseDiligence")
    public CommonResult<Object> saveDingFalseDiligence(@RequestBody SystemFalseDiligence dingFalseDiligence) {
        systemFalseDiligenceService.save(dingFalseDiligence);
        return CommonResult.success("操作成功");
    }

    @PostMapping("/removeDingFalseDiligence/{id}")
    public CommonResult<Object> removeDingFalseDiligence(@PathVariable(value = "id") Integer id) {
        systemFalseDiligenceService.remove(id);
        return CommonResult.success("操作成功");
    }

    @GetMapping("/selectDingFalseDiligencePage")
    public CommonResult<Object> selectDingFalseDiligencePage(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageInfo<SystemFalseDiligence> dingFalseDiligencePageInfo = systemFalseDiligenceService.selectPage(pageNum, pageSize, null);
        return CommonResult.success(dingFalseDiligencePageInfo);
    }

    @GetMapping("/selectList")
   public CommonResult<Object>  selectList(@RequestParam(value = "userId",required = false) String userId) {
        return CommonResult.success(systemFalseDiligenceService.selectList(userId));

    }

    @GetMapping("/getById")
    public CommonResult<Object> getById(@RequestParam("userId") String userId, @RequestParam("id") Integer id) {
    return CommonResult.success(systemFalseDiligenceService.getById(userId, id));
    }


}
